//
// Created by Administrator on 2025/4/20.
//

#include "Connection.h"


Connection::Connection(){
     mysql_init(&m_conn);
}
Connection::~Connection() {
    mysql_close(&m_conn);
}
bool Connection::connect(const char * host, const char * username, const char * password, const char * db,unsigned int port){
    if (mysql_real_connect(&m_conn, host, username, password, db, port, NULL, CLIENT_FOUND_ROWS)){
        return false;
    }
    return true;
}
bool Connection::update(const char * sql){
    if(mysql_query(&m_conn, sql)){
        return  false;
    }
    return true;
}
MYSQL_RES * Connection::query(const char * sql){
    if(mysql_query(&m_conn, sql)){
        return nullptr;
    }
    return mysql_use_result(&m_conn);
}